package com.sx.springbootshiro.service.impl;

import com.sx.springbootshiro.mapper.LoginUserMapper;
import com.sx.springbootshiro.model.LoginPermissionVB;
import com.sx.springbootshiro.model.LoginRolesVB;
import com.sx.springbootshiro.model.LoginUserVB;
import com.sx.springbootshiro.service.LoginUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.security.Permissions;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Service
public class LoginUserServiceImpl implements LoginUserService {
    @Autowired
    private LoginUserMapper loginUserMapper;

    @Override
    public List<LoginUserVB> selectLoginUserVBSByUseful() {
        return loginUserMapper.selectLoginUserVBSByUseful();
    }

    @Override
    public LoginUserVB selectLoginUserVBByNicknamePassword(String user_nickname, String user_password) {
        return loginUserMapper.selectLoginUserVBByNicknamePassword(user_nickname, user_password);
    }

    @Override
    public LoginUserVB selectLoginUserVBByUserNickname(String user_nickname) {
        LoginPermissionVB permissions1 = new LoginPermissionVB("1","query");
        LoginPermissionVB permissions2 = new LoginPermissionVB("2","add");

        Set<LoginPermissionVB> permissionsSet = new HashSet<>();
        permissionsSet.add(permissions1);
        permissionsSet.add(permissions2);

        LoginRolesVB role = new LoginRolesVB("1","admin",permissionsSet);
        role.setLoginPermissionVBS(permissionsSet);
        Set<LoginRolesVB> roleSet = new HashSet<>();
        roleSet.add(role);

        LoginUserVB loginUserVB = loginUserMapper.selectLoginUserVBByUserNickname(user_nickname);
        if (loginUserVB!=null){
            loginUserVB.setLoginRolesVBS(roleSet);
        }
        return loginUserVB;
    }

    @Override
    public boolean insetLoginUserVB(LoginUserVB loginUserVB) {
        return loginUserMapper.insetLoginUserVB(loginUserVB);
    }


}
